package com.bdsys.serviceimpl;

import java.util.ArrayList;
import java.util.List;

import com.bdsys.dao.DeviceDAO;
import com.bdsys.domain.DeviceDomain;
import com.bdsys.service.DeviceService;
import com.bdsys.servicedto.DeviceDetailDTO;
import com.bdsys.servicedto.DeviceServiceDTO;

public class DeviceServiceImpl implements DeviceService{
	
	DeviceDAO deviceDAO;
	
	public void setDeviceDAO(DeviceDAO deviceDAO){
		this.deviceDAO = deviceDAO;
	}
	
	public void addDevice(DeviceServiceDTO inServiceDTO){
		DeviceDetailDTO inDetailDTO = inServiceDTO.getDeviceDetailDTO();
		DeviceDomain inDomain = new DeviceDomain();
		inDomain.setDid(inDetailDTO.getDid());
		inDomain.setDname(inDetailDTO.getDname());
		inDomain.setDstatus(inDetailDTO.getDstatus());
		inDomain.setClassification(inDetailDTO.getClassification());
		deviceDAO.addDevice(inDomain);
	}

	@Override
	public DeviceServiceDTO selectAll() {
		List<DeviceDomain> list = deviceDAO.selectAll();
		
		List<DeviceDetailDTO> outList = new ArrayList<DeviceDetailDTO>();
		for(DeviceDomain outDomain : list){
			DeviceDetailDTO  outDeviceDetailDTO = new DeviceDetailDTO();
			outDeviceDetailDTO.setDid(outDomain.getDid());
			outDeviceDetailDTO.setDname(outDomain.getDname());
			outDeviceDetailDTO.setDstatus(outDomain.getDstatus());
			outDeviceDetailDTO.setClassification(outDomain.getClassification());
			outList.add(outDeviceDetailDTO);
		}
		
		DeviceServiceDTO outServiceDTO = new DeviceServiceDTO();
		outServiceDTO.setList(outList);
		return outServiceDTO;
	}

	@Override
	public DeviceServiceDTO selectByConditions(DeviceServiceDTO inServiceDTO) {
		DeviceDetailDTO inDetailDTO = inServiceDTO.getDeviceDetailDTO();
		DeviceDomain inDomain = new DeviceDomain();
		inDomain.setDid(inDetailDTO.getDid());
		inDomain.setDname(inDetailDTO.getDname());
		inDomain.setDstatus(inDetailDTO.getDstatus());
		inDomain.setClassification(inDetailDTO.getClassification());
		

		List<DeviceDomain> list = deviceDAO.selectByConditions(inDomain);
		
		List<DeviceDetailDTO> outList = new ArrayList<DeviceDetailDTO>();
		for(DeviceDomain outDomain : list){
			DeviceDetailDTO  outDeviceDetailDTO = new DeviceDetailDTO();
			outDeviceDetailDTO.setDid(outDomain.getDid());
			outDeviceDetailDTO.setDname(outDomain.getDname());
			outDeviceDetailDTO.setDstatus(outDomain.getDstatus());
			outDeviceDetailDTO.setClassification(outDomain.getClassification());
			outList.add(outDeviceDetailDTO);
		}
		
		DeviceServiceDTO outServiceDTO = new DeviceServiceDTO();
		outServiceDTO.setList(outList);
		return outServiceDTO;
	}

}
